/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.app.course.study.web;

import java.time.Duration;
import java.time.LocalDateTime;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.app.course.study.entity.AppCourseStudy;
import com.jeesite.modules.app.course.study.service.AppCourseStudyService;

/**
 * 课程学习表Controller
 * @author zpp
 * @version 2020-02-11
 */
@Controller
@RequestMapping(value = "${adminPath}/app/course/study/appCourseStudy")
public class AppCourseStudyController extends BaseController {

	@Autowired
	private AppCourseStudyService appCourseStudyService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AppCourseStudy get(String id, boolean isNewRecord) {
		return appCourseStudyService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("app:course:study:appCourseStudy:view")
	@RequestMapping(value = {"list", ""})
	public String list(AppCourseStudy appCourseStudy, Model model) {
		model.addAttribute("appCourseStudy", appCourseStudy);
		return "modules/app/course/study/appCourseStudyList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("app:course:study:appCourseStudy:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<AppCourseStudy> listData(AppCourseStudy appCourseStudy, HttpServletRequest request, HttpServletResponse response) {
		appCourseStudy.setPage(new Page<>(request, response));
		Page<AppCourseStudy> page = appCourseStudyService.findPage(appCourseStudy);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("app:course:study:appCourseStudy:view")
	@RequestMapping(value = "form")
	public String form(AppCourseStudy appCourseStudy, Model model) {
		model.addAttribute("appCourseStudy", appCourseStudy);
		return "modules/app/course/study/appCourseStudyForm";
	}

	/**
	 * 保存课程学习表
	 */
	@RequiresPermissions("app:course:study:appCourseStudy:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated AppCourseStudy appCourseStudy) {
		appCourseStudyService.save(appCourseStudy);
		return renderResult(Global.TRUE, text("保存课程学习表成功！"));
	}
	
	/**
	 * 停用课程学习表
	 */
	@RequiresPermissions("app:course:study:appCourseStudy:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(AppCourseStudy appCourseStudy) {
		appCourseStudy.setStatus(AppCourseStudy.STATUS_DISABLE);
		appCourseStudyService.updateStatus(appCourseStudy);
		return renderResult(Global.TRUE, text("停用课程学习表成功"));
	}
	
	/**
	 * 启用课程学习表
	 */
	@RequiresPermissions("app:course:study:appCourseStudy:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(AppCourseStudy appCourseStudy) {
		appCourseStudy.setStatus(AppCourseStudy.STATUS_NORMAL);
		appCourseStudyService.updateStatus(appCourseStudy);
		return renderResult(Global.TRUE, text("启用课程学习表成功"));
	}
	
	/**
	 * 删除课程学习表
	 */
	@RequiresPermissions("app:course:study:appCourseStudy:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(AppCourseStudy appCourseStudy) {
		appCourseStudyService.delete(appCourseStudy);
		return renderResult(Global.TRUE, text("删除课程学习表成功！"));
	}
	public static void main(String[] args) {
		LocalDateTime now=LocalDateTime.now();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		LocalDateTime curr=LocalDateTime.now();
		Duration between = Duration.between(now, curr);
		long millis = between.toMillis();
		System.out.println(millis);
	}
}